import { useUserStore } from "@/stores/user";
import request from "@/utils/request";

// 模拟登陆，实际需要调用request进行登录请求
export function login(username, password) {
    return new Promise((resolve, reject) => {
        if (username == 'admin' && password == 'admin123') {
            resolve({
                code: 200,
                msg: '请求成功',
                token: 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJhZG1pbiIsInNleCI6bnVsbCwicm9sZXMiOm51bGwsImF2YXRhciI6InVwbG9hZC8yMDI1LzAzLzIwLzg0ZTZhYTEwMWRkMTRhNDNiMGFkYmQxNDJkZjA4NDcyLnBuZyIsImF1dGhvcml0aWVzIjpbIkFETUlOIl0sImNsaWVudF9pZCI6ImNsaWVudC1hcHAiLCJsYXN0TG9naW5JcCI6IjEyNy4wLjAuMSIsImxhc3RMb2dpblRpbWUiOm51bGwsInBhc3N3b3JkIjoiJDJhJDEwJFFITTc4NXFVQi5BM1BEdVBPMURwZS5GajRaMUVFZGhoT1VOV2lMQ1FkV1VLb1c1VGxIV3UyIiwicGhvbmUiOiIxNTI2OTE2NzA2NSIsInNjb3BlIjpbImFsbCJdLCJsb2dpbk5hbWUiOiJhZG1pbiIsImlkIjoxLCJleHAiOjE3NDM2NTkwMTEsImp0aSI6InFua0s1bzZwdklnRGdlRVlvWks5VGZ4SmkyayIsImVtYWlsIjoiMTIzQHFxLmNvbSIsInVzZXJuYW1lIjoi566h55CG5ZGYIn0.JLiIknMWIB6iE2tDu6Z0_ulJoDcEOwDq_YWwV53cWUq-ggAGeKaTws2GsfrQzCALVqjve769Q1YnEW0x2xMzbHIg0IGDw5qZHiy2-Q6IV_vQpIuTQGwqnG60KOYFeRM1Zck0At6XpqG9r7zyAJEEN7HLSnC3-2JcrLl23fSCDeHNCBEi5HTvkxsZ7iz5_9RK2zOuL3cJf1XSLSFViy43xX6vNPauhNLh9HHP-xpe5HXfyXjw-TOYfqNqXk5rzZrhJDEYHCfI01Bgzmals4_GzmL1t3soqMZXY3Y_9YO30WEDIaun0CfM_jdMxLWJNUCv5-iZ43QYXqqp-3XoyBR1_Q'
            })
        } else if (username == 'user1' && password == 'user1') {
            resolve({
                code: 200,
                msg: '请求成功',
                token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJRUToyMzc5NzIxMTMiLCJuYW1lIjoidXNlcjAxIiwiaWF0IjoxNTE2MjM5MDIyfQ.7H5YJp0vmJym6cYp_pALEQEaj6pPZWVvea1vm8uIMJQ'
            })
        } else {
            reject('账号密码错误');
        }
    });
}

// 模拟请求用户信息，正常是需要经过后端校验token后判断登录用户再进行返回数据
export function getInfo(token) {
    const userStore = useUserStore();
    return new Promise((resolve, reject) => {
        if (token == 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJhZG1pbiIsInNleCI6bnVsbCwicm9sZXMiOm51bGwsImF2YXRhciI6InVwbG9hZC8yMDI1LzAzLzIwLzg0ZTZhYTEwMWRkMTRhNDNiMGFkYmQxNDJkZjA4NDcyLnBuZyIsImF1dGhvcml0aWVzIjpbIkFETUlOIl0sImNsaWVudF9pZCI6ImNsaWVudC1hcHAiLCJsYXN0TG9naW5JcCI6IjEyNy4wLjAuMSIsImxhc3RMb2dpblRpbWUiOm51bGwsInBhc3N3b3JkIjoiJDJhJDEwJFFITTc4NXFVQi5BM1BEdVBPMURwZS5GajRaMUVFZGhoT1VOV2lMQ1FkV1VLb1c1VGxIV3UyIiwicGhvbmUiOiIxNTI2OTE2NzA2NSIsInNjb3BlIjpbImFsbCJdLCJsb2dpbk5hbWUiOiJhZG1pbiIsImlkIjoxLCJleHAiOjE3NDM2NTkwMTEsImp0aSI6InFua0s1bzZwdklnRGdlRVlvWks5VGZ4SmkyayIsImVtYWlsIjoiMTIzQHFxLmNvbSIsInVzZXJuYW1lIjoi566h55CG5ZGYIn0.JLiIknMWIB6iE2tDu6Z0_ulJoDcEOwDq_YWwV53cWUq-ggAGeKaTws2GsfrQzCALVqjve769Q1YnEW0x2xMzbHIg0IGDw5qZHiy2-Q6IV_vQpIuTQGwqnG60KOYFeRM1Zck0At6XpqG9r7zyAJEEN7HLSnC3-2JcrLl23fSCDeHNCBEi5HTvkxsZ7iz5_9RK2zOuL3cJf1XSLSFViy43xX6vNPauhNLh9HHP-xpe5HXfyXjw-TOYfqNqXk5rzZrhJDEYHCfI01Bgzmals4_GzmL1t3soqMZXY3Y_9YO30WEDIaun0CfM_jdMxLWJNUCv5-iZ43QYXqqp-3XoyBR1_Q') {
            resolve({
                code: 200,
                msg: '请求成功',
                data: {
                    userId: 1,
                    userName: 'Coder_xiaoyi',
                    nickName: '小兵良品',
                    avatar: '',
                    permissions: ['*:*:*'],
                    roles: ['admin']
                }
            })
        } else if (token == 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJRUToyMzc5NzIxMTMiLCJuYW1lIjoidXNlcjAxIiwiaWF0IjoxNTE2MjM5MDIyfQ.7H5YJp0vmJym6cYp_pALEQEaj6pPZWVvea1vm8uIMJQ') {
            resolve({
                code: 200,
                msg: '请求成功',
                data: {
                    userId: 2,
                    userName: 'user1',
                    nickName: '用户1',
                    avatar: 'https://files.catbox.moe/zfaaqx.jpg',
                    permissions: ['test:list'],
                    roles: ['user1']
                }
            })
        } else {
            resolve({
                code: 403,
                msg: 'token已失效',
                data: {}
            })
        }

    });
}

// 模拟请求用户信息，正常是需要传入token后进行登出
export function logout(token) {
    return new Promise((resolve, reject) => {
        resolve({
            code: 200,
            msg: '退出成功'
        })
    });
}
